<template>
  <div>
    <el-dialog
      title="新增工单"
      :visible.sync="dialogVisible"
      width="45%"
      @close="offDialogG"
    >
      <div class="form">
        <el-form ref="form" :model="form" label-width="100px" :rules="rules">
          <el-form-item label="设备编号：" prop="innerCode">
            <el-input
              v-model="form.innerCode"
              type="text"
              placeholder="请输入内容"
              maxlength="15"
              show-word-limit
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item label="工单类型：" prop="taskType">
            <el-select v-model="form.productType" placeholder="请选择" style="width: 300px">
              <el-option label="投放工单" :value="1" />
              <el-option label="维修工单" :value="3" />
              <el-option label="撤机工单" :value="4" />
            </el-select>
          </el-form-item>

          <el-form-item label="运维人员：" prop="userName">
            <el-select v-model="form.userId" placeholder="请选择" style="width: 300px" @click.native="getOperation">
              <el-option
                v-for="item in options"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注：" prop="desc">
            <el-input
              v-model="form.desc"
              type="textarea"
              placeholder="请输入备注(不超过40字)"
              maxlength="40"
              show-word-limit
              :rows="3"
              style="width: 300px"
            />
          </el-form-item>
        </el-form>
      </div>

      <span slot="footer">
        <!-- 新增 -->
        <div class="footer">
          <el-button style="background-color: #fbf4f0;color: #606266;" @click="offDialogG">取 消</el-button>
          <el-button style="background-color: #ff6726;color:#fff" @click="submit">确 定</el-button>
        </div>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getOperationList, addOrder, getOrderDetail } from '@/api/lmoperation'

export default {
  name: 'DialogLm',
  components: {

  },
  props: {
  },
  data() {
    return {
      dialogVisible: false,
      form: {
        innerCode: '', // 设备编号
        productType: '', // 工单类型
        userId: '', // 运营人员
        desc: '', // 备注
        createType: 1 // 创建类型 运维
      },
      rules: {
        innerCode: [{ required: true, message: '请输入', trigger: 'blur' }], // 设备编号
        taskType: [{ required: true, message: '请选择', trigger: 'blur' }], // 工单类型
        userName: [{ required: true, message: '请选择', trigger: 'blur' }], // 运营人员
        desc: [{ required: true, message: '请输入', trigger: 'blur' }] // 备注
      },
      // 运维人员集合
      options: [],
      orderdata: {}
    }
  },
  methods: {
    // 弹窗显示
    async openDialogK(id) {
      const data = await getOrderDetail(id)
      // console.log(data)
      this.orderdata = data
      this.form.productType = data.productTypeId
      this.form.innerCode = data.innerCode
      this.form.userId = data.userName
      this.form.desc = data.desc

      this.dialogVisible = true
    },
    // 弹窗显示
    openDialog() {
      this.dialogVisible = true
    },
    // 弹窗关闭
    offDialogG() {
      this.$refs.form.resetFields()
      this.dialogVisible = false
      this.form.productType = ''
      this.form.userId = ''
    },
    // 获取运维人员
    async getOperation() {
      const data = await getOperationList(this.form.innerCode)
      this.options = data
      // console.log(data)
    },
    // 确定
    async submit() {
      try {
        if (this.form.userId === this.orderdata.userName) {
          this.form.userId = this.orderdata.userId
        }

        await addOrder(this.form)
      } catch (error) {
        // console.dir(error.response.data)
        // 重新创建的时候，需要换一个工单类型
        this.$message.warning(error.response.data)
        this.dialogVisible = false
      }
    }
  }
}
</script>

<style scoped lang='scss'>
.footer{
  padding-right: 36%;
}
.foot{
  padding-right: 42%;
}
.form{
  padding-left: 50px;
}
.detail{
  width: 100%;
  height: 200px;
  .todo{
    width: 100%;
    height: 50px;
    line-height: 50px;
    background-color: #f8f8f8;
    margin-bottom: 20px;
    padding-left: 20px;
    padding-right: 80px;
    .image{
      vertical-align: middle;
    }
    .text{
      font-size: 16px;
      margin-left: 10px;
      display: inline-block;
      vertical-align: middle;
    }
    .images{
      width: 14%;
      float: right;
    }
  }
  .left{
    padding-left: 50px;
  }
}
</style>
